<?php

namespace Repository;

use Doctrine\ORM\EntityRepository;

class LogRepository extends EntityRepository {
	public function saveLog($data, $status, $mess){
		
		$u = $this->_em->getRepository('Entity\ShUser')->findOneById($data);

		$l = new \Entity\ShLog();
		$l->setShUser($u);
		$l->setObject($status);
		$l->setMessage($mess);
		$l->setDate(time());

		$this->_em->persist($l);
		$this->_em->flush();
	}
	public function getLogBy($data){
		$q = $this->_em->createQueryBuilder()
		->select('lg')
		->from('Entity\ShLog','lg')
		->where('lg.id =?1')
		->setParameters(array(
			1 => $data
			));
		return $q->getQuery()->getResult();
	}
	public function deleteAll(){
		$q = $this->_em->createQuery('delete from Entity\ShLog');
		$q->execute();
		return true;
	}
	public function backendPaginate($conf){
		$q = $this->_em->getRepository('\Entity\ShLog')->findBy(
			$conf['condition'],$conf['order'],$conf['limit'],$conf['offset']
			);
		return $q;
	}
	public function total_rows($pag){
		$q=  $this->_em->createQueryBuilder()
		->select('COUNT(l.id)')
		->from('Entity\ShLog','l');
		return $q->getQuery()->getSingleScalarResult();
	}
}